﻿using MediatR;
using ProductIntory.Domains;
using ProductIntory.ErrorCodes;
using ProductIntory.Infrastructures.Interface;
using ProductIntory.Read.Apis.Application.Command.ProductsCommands;

namespace ProductIntory.Read.Apis.Application.CommandHandler.ProductionCommandHandlers
{
    public class UpdateProductsCommandHandler : IRequestHandler<UpdateProductsCommand, ApiResult<int>>
    {
        IBaseRepository<Products> Products;

        public UpdateProductsCommandHandler(IBaseRepository<Products> Products)
        {
            this.Products = Products;
        }

        public async Task<ApiResult<int>> Handle(UpdateProductsCommand request, CancellationToken cancellationToken)
        {
            await Products.Update(request.Products);
            return new ApiResult<int>
            {
                Code = ApiEnum.success,
                Message = "修改成功",
                Data = 1
            };
        }
    }
}
